<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <button onclick="JZ()">加载</button>

    <script>
    function JZ(params) {
       
        function success(text) {
            var textarea = document.getElementById('app');
            textarea.innerHTML = text;
        }

        function fail(code) {
            var textarea = document.getElementById('app');
            textarea.innerHTML = 'Error code: ' + code;
        }
        
        let request ; // 新建XMLHttpRequest对象
        if(window.XMLHttpRequest){
            request = new XMLHttpRequest();
            console.log("XMLHttpRequest");
        }else{
            request = new ActiveXObject("Microsoft.XMLHTTP")
            console.log("XMLHTTP");
        }  
       
        
        
        request.onreadystatechange = function () { // 状态发生变化时，函数被回调
            if (request.readyState === 4) { // 成功完成
                // 判断响应结果:
                if (request.status === 200) {
                    // 成功，通过responseText拿到响应的文本:
                    return success(request.responseText);
                } else {
                    // 失败，根据响应码判断失败原因:
                    return fail(request.status);
                }
            } else {
                // HTTP请求还在继续...
            }
        }

        // 发送请求:
        request.open('GET', 'http://127.0.0.1:1337/');
        request.send();

        console.log('请求已发送，请等待响应...');
    }
        
    </script>
</body>

</html>